<template>
	<view class="messageC">
		<view class="mesItem" v-for="(item , index) in messageList" :key="index" @tap="skipPage(item)">
			<view>
				<view class="mesTitle">{{item.title}}</view>
				<view class="mesContent">详情 : {{item.content}}</view>
			</view>
			<view 
			v-if = "item.is_read == 1"
			style="color: red; font-weight: 800; font-size: 35rpx;">未读</view>
			<view 
			v-if = "item.is_read == 2"
			style="color: blue; font-weight: 800; font-size: 35rpx;">已读</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				messageList : [],
				user_sn : "",//用户工号
				is_read : false ,//标记信息是否已读
			}
		},//data
		async onShow(){
			await this.getUserInfo();
			this.getMessage();
		},//onShow
		methods: {
			getMessage(){
				let params= {
					user_sn : this.user_sn
				};
				this.http.get("/messages/getList" , params)
				.then((res)=>{
					console.log("获取消息列表-成功");
					console.log(res);
					if(res.code != 1){
						return;
					}			
					this.messageList = res.data;
				})
				.catch((err)=>{
					console.log("获取消息列表-失败");
					console.log(err);
				});
			},
			
			skipPage(item){
				uni.navigateTo({
					url: `/pages/tab4/messageDetail?id=${item.id}`
				})
			},
			
			async getUserInfo() {
			  if (!uni.getStorageSync("token")) return;
			  const data = await this.http.get("user/getUerInfo");
			  console.log("这里是用户信息");
			  console.log(data);
			  this.user_sn = data.data.user_sn;
			  			  
			},
			
		},//methods
	}
</script>

<style scoped lang="scss">
.messageC{
	background-color: #f5f5f5;
	height: 100vh;
	overflow-y: scroll;
}

.mesItem{
	box-sizing: border-box;
	padding: 15rpx;
	margin-top: 20rpx;
	border-radius: 20rpx;
	background-color: #fff;
	margin-left: 20rpx;
	margin-right: 20rpx;
	display: flex;
	align-items: center;
}

.mesTitle{
	width: 250rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-weight: 800;
	font-size: 35rpx;
}
.mesContent{
	width: 600rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-size:30rpx;
}

</style>
